import requests
for i in range(1, 6):
    url = 'http://www.bspider.top/qidian/?'
    head = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'}
    data = {'page': i}
    try:
        r = requests.get(url=url,params=data,headers=head)
        r.encoding = r.apparent_encoding
        r.raise_for_status()
        with open('qidiantop.txt', 'a', encoding='utf-8')as fp:
            fp.write(r.text)

    except Exception as err:
        print(err)

